﻿// code02050200.cpp : 处理类型
// auto类型

#include <iostream>
using namespace std;

int main()
{
    auto i = 0, * p = &i;
    auto sz = 0, pi = 3.14;//报错！auto已经推断为int，却需要推断为double

    int i = 0, & r = i; //auto推断为int
    auto a = r;//r是整型的引用，auto推断为int
    const int ci = i, & cr = ci;
    auto b = ci;//ci是常量，auto推断为int
    auto c = cr;//cr是引用，auto推断为int
    auto d = &i;//&i是变量地址，auto推断为int*
    auto e = &ci;//&ci是常量地址，auto推断为const int*
    const auto f = ci;//ci是常量，auto推断为int
    auto& g = ci;//ci是int型常量，auto推断为cosnt int
    auto& h = 42;//报错！42是字面值常量，无法引用
    const auto& j = 42;//42是字面值常量，可能被const auto引用

    auto k = ci, & l = i;//auto被推断为int
    auto& m = ci, *p1 = &ci;//前被推断为const int，后被推断为const int
    auto& n = i, *p2 = &ci;//报错！前被推断为int，后被推断为const int

    return 0;


}

